package com.dsbj.icardservice.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dsbj.icardservice.entity.District;
import com.dsbj.icardservice.entity.Employee;
import com.dsbj.icardservice.mapper.DistrictMapper;
import com.dsbj.icardservice.mapper.EmployeeMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author cjw 2019-09-24
 */
@Service
@Transactional
public class DistrictService extends ServiceImpl<DistrictMapper, District> {

	@Resource
	private DistrictMapper districtMapper;


	/**
	 * 根据districtno模糊查询district信息。
	 * @param
	 * @return
	 * @author cjw 2019-09-23
	 */
	public List<District> getDistrictByNoDim(String districtno){

		QueryWrapper<District> queryWrapper=new QueryWrapper<>();
		queryWrapper.like("DISTRICTNO",districtno);
		queryWrapper.orderByDesc("CREATE_TIME");
		List<District> districts=districtMapper.selectList(queryWrapper);
		return districts;
	}

	/**
	 * 根据districtname模糊查询district信息。
	 * tip1: districtname中亦可传入districtno。
	 * @param
	 * @return
	 * @author cjw 2019-09-23
	 */
	public List<District> getDistrictByNameDim(String districtName){

		QueryWrapper<District> queryWrapper=new QueryWrapper<>();
		queryWrapper.and(i->i.like("DISTRICTNO",districtName).or().like("DISTRICT_NAME",districtName))
				.orderByDesc("CREATE_TIME");
		List<District> districts=districtMapper.selectList(queryWrapper);
		return districts;
	}

	/**
	 * 获取districts。
	 * @param
	 * @param companyno
	 * @return
	 * @author cjw 2019-09-26
	 */
	public List<District> getDistricts(String companyno){
		QueryWrapper<District> queryWrapper=new QueryWrapper<>();
		queryWrapper.select("ID","DISTRICTNO","BUILD","FLOOR","DISTRICT_NAME").eq("COMPANYNO",companyno);
		List<District> districts=districtMapper.selectList(queryWrapper);
		return districts;
	}



}
